const {
  $util,
} = getApp();
const MAX_LENGTH = 10;
Page({
  data: {
    page: 1,
    list: [],
    hasMore: true,
    isSearch: false,
    typ: 0,
    nav: [{
      title: '待评议',
      id: 0,
    }, {
      title: '已评议',
      id: 1,
    }],
    bgColor: ['#FF0026', '#FF9500', '#FFCC00', '#27BF76', '#32C5FF', '#4185F4', '#5856D6', '#FF2D55'],
  },
  onLoad(ops) {
    wx.setNavigationBarTitle({
      title: '民主评议',
    });
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
  },
  changeNav(e) {
    this.setData({
      page: 1,
      typ: e.detail.obj.id,
    }, () => {
      this.loadList();
    });
  },
  onReachBottom() {
    this.data.hasMore && this.loadList();
  },
  loadList() {
    const {
      page,
      typ: type,
      list: d_list,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/partylife.review',
      data: {
        page,
        type,
      },
      success: (res) => {
        let list = res.data;
        if (page > 1) {
          list = [...d_list, ...list];
        }
        this.setData({
          list,
          page: res.data.length === MAX_LENGTH ? page + 1 : page,
          hasMore: res.data.length === MAX_LENGTH,
          isLoad: true,
        });
      },
    });
  },
});